package com.bjsxt.userCenter.common.util;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;

public class FileUtil
{
	public InputStream is;
	
	public static String getCodeInfo(File file)
	{
		try
		{
			InputStream is = new FileInputStream(file);
			 return getCodeInfo(is);
		} catch (FileNotFoundException e)
		{
			ConstantFinalUtil.LOGGER.error("读取资源文件出错",e);
		}
		return "";
	}
	
	public static String getCodeInfo(InputStream is)
	{
		StringBuilder sb = new StringBuilder();
		BufferedReader br = null;
		try
		{
			br = new BufferedReader(new InputStreamReader(is,"UTF-8"));
			String line = "";
			while((line = br.readLine()) != null)
			{
			  line = line.trim();
			  if(line.startsWith("//"))
			  {
				  continue;
			  }
			  sb.append(line);
			}
		} catch (Exception e)
		{
			ConstantFinalUtil.LOGGER.error("读取资源文件出错",e);
		} finally
		{
			if(br != null)
			{
				try
				{
					br.close();
				} catch (IOException e)
				{
					e.printStackTrace();
				}
			}
		}
		return sb.toString();
	}
	
	/*public static void main(String[] args)
	{
		String result = getCodeInfo(FileUtil.class.getClassLoader().getResourceAsStream(""));
		System.out.println(result);
	}*/
}
